/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package processer;

import main.BotManager;
import utils.Debug;
import utils.Utils;

/**
 *
 * @author Administrator
 */
public class RoomChooser extends Processer {

    private int roomSelectedIndex;
    private boolean isWaitingMoney;

    public RoomChooser(RoBot parent, GameData gameData, BotManager manager) {
        super(parent, gameData, manager);
        findRoom();
    }

    private void findRoom() {
        isWaitingMoney = false;
        roomSelectedIndex = Utils.nextInt(10);
        if (roomSelectedIndex > 6) {
            int r = Utils.nextInt(100);
            if (r % 10 != 0) {
                roomSelectedIndex = Utils.nextInt(4);
            }
        }
        if (Debug.isTest) {
            roomSelectedIndex = 0;
        }
        parent.request.enterRoom(roomSelectedIndex);
    }

    @Override
    public void processMesage(String[] part) {
        Debug.d("process room chooser :" + part[0]);
        super.processMesage(part);
        if (part[0].equals("SM")) {
            gameData.setTableMoneyBet(part);
            return;
        }

        if (part[0].equals("US")) {
            gameData.setTableMax(part);
            return;
        }
        if (part[0].equals("SE")) {
            gameData.setNumberPlayerInTable(part);
            gameData.setRoomId(roomSelectedIndex);
            parent.changeProcesser(RoBot.TABLE_CHOOSER);
            return;
        }
        if (part[0].equals("RGA")) {
            parent.changeProcesser(RoBot.GAME_CHOOSER);
            return;
        }
        if (part[0].equals("PASS")) {
            gameData.setTablePass(part);
            return;
        }
        if (part[0].equals("NSE")) {
            parent.request.setMoney(Integer.parseInt(part[1]));
            isWaitingMoney = true;
            return;
        }
        if (part[0].equals("SETMONEY")) {
            gameData.myMoney = Integer.parseInt(part[1]);
            if (isWaitingMoney) {
                parent.request.exitChooseRoom();
            }
            return;
        }

    }

    @Override
    public void doLoop() {
    }
}
